基于51单片机实现的音乐电子贺卡使用Proteus 进行模拟 #include <reg51.h>
#define u8 unsigned char
#define u16 unsigned int
sbit BEEP=P2^3;
void delay_ms(u16 x)
{u16 i,j;
for(i=0;i<x;i )
for(j=0;j<115;j );
}
u8 code SONG_TONE[]={212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126,159,142,159,0};
u8 code SONG_LONG[]={9,3,12,12,12,24,9,3,12,12,12,24,9,3,12,12,12,12,12,9,3,12,12,12,24,0};
void PlayMusic()
{
u16 i=0,j,k;
while(SONG_LONG[i]!=0||SONG_TONE[i]!=0)
{
for(j=0;j<SONG_LONG[i]*20;j )
{
BEEP=~BEEP;
for(k=0;k<SONG_TONE[i]/3;k );
}
delay_ms(10);
i ;
}
}
void main()
{
PlayMusic();
while(1);
}.
├── 示例5:音乐贺卡
│ ├── project5
│ │ ├── STARTUP.A51
│ │ ├── STARTUP.LST
│ │ ├── STARTUP.OBJ
│ │ ├── main.LST
│ │ ├── main.OBJ
│ │ ├── main.c
│ │ ├── project
│ │ ├── project.M51
│ │ ├── project.hex
│ │ ├── project.lnp
│ │ ├── project.plg
│ │ ├── project.uvopt
│ │ ├── project.uvproj
│ │ ├── project_uvopt.bak
│ │ └── project_uvproj.bak
│ ├── 蜂鸣器.DSN
│ └── 蜂鸣器.PWI
└── 找例子网_音乐贺卡.zip
2 directories, 18 files
评论